﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AutoClearFolder
{
    class Program
    {
        static void Main(string[] args)
        {
            var day = AppConfig.Instance.GetValue("Day");

            var delDay = 3;
            if (day != null)
                delDay = int.Parse(day);

            var aList = GetDelFolderList();

            aList.ForEach(folder =>
            {
                var b7 = Directory.GetDirectories(folder).Select(d => new DirectoryInfo(d)).Where(d => d.CreationTime < DateTime.Now.AddDays(-delDay) && d.GetFiles().Length > 0);
                foreach (var s in b7)
                {
                    s.Delete(true);
                }
            });
        }

        /// <summary>
        /// 获取要删除的路径集合
        /// </summary>
        /// <returns></returns>
        public static List<string> GetDelFolderList()
        {
            var aList = new List<string>();

            for (var i = 1; i < 30; i++)
            {
                var value = AppConfig.Instance.GetValue("Folder" + i);
                if (!string.IsNullOrWhiteSpace(value))
                {
                    aList.Add(value);
                }
            }

            return aList;
        }
    }
}
